import React, { useEffect,useState } from 'react'
import axios from 'axios';
import { useRequest } from 'ahooks';
import {message} from 'antd';
import NewsPublishTable from '@/components/NewsPublishTable';
import usePublish from '@/util/usePublish';

//#region 不封装，不使用自定义hooks的方案
// 发起网络请求，发布管理-待发布页面，要显示当前用户+发布状态（publishState===1）为 待发布 所有新闻信息,
const getUnpublishedRequest = (userName: string) => {
    return axios.get(`http://localhost:3000/news?_expand=category&author=${userName}&publishState=1`);
};
//#endregion


export default function Unpublished() {
    //从localStorage获取当前用户信息
    const currentUser = JSON.parse(localStorage.getItem('token') as string);
    //#region 不封装，不使用自定义hooks的方案
    // 表格数据源保存
    // const[dataSource,setDataSource]=useState<any>([]);
    // useRequest - 获取当前用户待发布新闻（publishState===1）信息
    // const { run: getUnpublishedData, loading: getUnpublishedLoading } = useRequest(getUnpublishedRequest, {
    //     throttleWait: 300,
    //     manual: true,
    //     onSuccess: (result: any, params) => {
    //         if (result.status === 200) {
    //             setDataSource(result.data)
    //         }
    //     },
    //     onError(e, params) {
    //         message.warning('请求待发布的新闻数据失败');
    //     },
    // });
    // useEffect(()=>{
    //     getUnpublishedData(currentUser[0].username);
    // },[currentUser[0].username])
    //#endregion
    
    const {dataSource}=usePublish(1);
    return (
        <div>
            <NewsPublishTable dataSource={dataSource}></NewsPublishTable>
            {/* <NewsPublishTable dataSource={dataSource} tableLoading={getUnpublishedLoading} getDataSource={getUnpublishedData}></NewsPublishTable> */}
        </div>
    )
}
